package com.starsea.book.ui.newpage.adapter

import android.content.Context
import android.view.ViewGroup
import com.starsea.book.base.adapter.ItemViewHolder
import com.starsea.book.base.adapter.RecyclerAdapter
import com.starsea.book.databinding.ItemShelfBookCoverBinding
import com.starsea.book.ui.newpage.entity.BookInfoEntity
import com.starsea.book.ui.newpage.utils.loadNormalImage

class HomeShelfGroupBookImgAdapter(
    context: Context,
    var onChanged: (() -> Unit)? = null
) :
    RecyclerAdapter<BookInfoEntity, ItemShelfBookCoverBinding>(context) {


    override fun getViewBinding(parent: ViewGroup): ItemShelfBookCoverBinding {
        return ItemShelfBookCoverBinding.inflate(inflater, parent, false)
    }

    override fun registerListener(holder: ItemViewHolder, binding: ItemShelfBookCoverBinding) {
        holder.itemView.apply {
            setOnClickListener {
                onChanged!!.invoke()
            }
        }
    }

    override fun convert(
        holder: ItemViewHolder,
        binding: ItemShelfBookCoverBinding,
        item: BookInfoEntity,
        payloads: MutableList<Any>
    ) {
        binding.run {
            ivCover.loadNormalImage(context, item.bookCover ?: "")
        }
    }


}